package edu.arizona.sista.learn.model.inferences;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * A class to launch the inference process
 */

public class Inferences {
	/**
	 * Loads ground predicates and rules and performs inferences.
	 * @param groundPredicateFile the file containing the ground predicates
	 * @param ruleFile the file containing the rules
	 * @param outputFile the file in which to save the inferred predicates
	 * @throws FileNotFoundException 
	 */
	public static void computeInferences(String groundPredicateFile, String ruleFile, String outputFile) throws FileNotFoundException{
		//Load ground predicates
		List<Predicate> listPred = loadGroundPredicates(groundPredicateFile);
		
		//Load rules
		
		//perform inferences (i.e. update ground predicates using rules)

		//save inferred ground predicate into output file
	}

	private static List<Predicate> loadGroundPredicates(String groundPredicateFile) throws FileNotFoundException {
		List<Predicate> listPred = new ArrayList<Predicate>();
		Scanner scanner = new Scanner(new File(groundPredicateFile));
		while(scanner.hasNextLine()) insert(listPred, new Predicate(scanner.nextLine()));
		return listPred;
	}

	private static void insert(List<Predicate> listPred, Predicate p1) {
		for (Predicate p2 : listPred) if (p1.equals(p2)) return;
		listPred.add(p1);		
	}
}
